<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>新增用户</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.query.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	if($.query.get('r')=='s'){
		alert('添加管理员成功');
	}else if($.query.get('r')=='e'){
		alert('抱歉，添加失败！请刷新页面重试，如果问题依然存在，请与维护人员联系');
	}
	$('#username').blur(function(){
		$('#hint_username').css('color','red');
		if($('#username').val()==""){
			$('#hint_username').html('*账号不能为空');
		}else{
			$.post("AjaxAction!checkAdminUser.action",{
				username : $('#username').val()
			},function(data){
				if(data[0].result=="yes"){
					$('#hint_username').css('color','green');
					$('#hint_username').html('√');
				}else if(data[0].result=="logout"){
					alert('登陆超时!');
					parent.window.location.href='login.html';
				}else if(data[0].result=="permission denied"){
					alert('抱歉，您当前登录的管理员没有该项权限！');
				}else if(data[0].result=="exist"){
					$('#hint_username').html('该账号已经存在！');
				}
			},"json");
		}
	});
});

function addUser(){
	if($('#username').val()==""){
		$('#hint_username').css('color','red');
		$('#hint_username').html('*账号不能为空');
		return false;
	}
	if($('#password').val()==""){
		$('#hint_password').html('*密码不能为空');
		return false;
	}else{
		$('#hint_username').html('*');
	}
	$('#myForm').submit();
}
</script>
</head>
<body style="background-image:url(./images/homelogo.png);background-color:#004350">
<div style="position: relative; margin-left: 450px; margin-top: 200px; width: 400px">
		<form action="UserAction!addUser.action" method="post"
			name="myForm" id="myForm">
		<p>
			<label>用户账号</label> <input type="text" name="user.username"
				id="username" /><span id="hint_username" style="color: red">*</span>
		</p>
		<p>
			<label>用户密码</label> <input type="password" name="user.password"
				id="password" /><span id="hint_password" style="color: red">*</span>
		</p>
		<p>
			<label>用户权限</label> <select name="user.role" id="role">
					<option value="0">超级管理员</option>
					<option value="1">A10公寓管理员</option>
					<option value="2">A17公寓管理员</option>
					<option value="3">B04公寓管理员</option>
					<option value="4">B06公寓管理员</option>
				</select>
		</p>
		<p>
			<label>用户姓名</label> <input type="text" name="user.realname"
				id="realname" />
		</p>
		<p style="text-align: center; width: 240px; margin-left:20px;">
				<input type="button" class="button" onclick="addUser();"
					value="增加" /> <input type="button" class="button" value="返回"
					onclick="javascript:location.href='main.html';" />
			</p>
		</form>
	</div>
</body>
</html>